#pragma once
#include "Part.h"
#include "Common/CollectDefine.h"

class CollectPart : public Part
{
	typedef void (CollectPart::*pFunc)(const char*, uint32_t);
	typedef std::map<uint32_t, pFunc> mapMsgFunc;
	mapMsgFunc   m_mapMsgfunc;

public:
	CollectPart();
	virtual ~CollectPart();

public:
	virtual bool		Init(Creature *pMaster, uint32_t partType, CharacterDBInfo* pCharacterDB = nullptr);
	virtual bool		UnInit();
	virtual bool		OnMsgHandle(uint32_t cmd, const char* data, uint32_t len);
	virtual void		OnExecute(uint16_t nEventID, uint64_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen);
	virtual void		OnTimer(uint32_t nTimerID);
	virtual bool		SaveDB(CharacterDBInfo& characterDB) { return true; }

public:
	void				Collect(const char *data, uint32_t len);
	void				Qte(const char *data, uint32_t len);
	void				CollectSpecial(const char *data, uint32_t len);
	void				AddCollectSpeed(int32_t rate);						//collect speed
	void				DecCollectSpeed(int32_t rate);
	CollectData_Type	GetCollecType() { return m_curState.byType; }
	void				BroadcastCollectAction();

private:
	bool				CheckPeel(CharIDType cid, uint32_t &cfgId);		//check剥皮
	bool				CheckRes(uint32_t cfgId, const ThingCollectCfgInfo *pCollectCfg);
	bool				CheckCond(const ThingCollectCfgInfo *pCollectCfg);
	void				CollectBegin(const ThingCollectCfgInfo *pCfg, CollectOperateReq &req);
	void				CollectFinish(ERetCode &retcode);
	void				NotifyState(int32_t state, bool begin = true);
	void				NotifyError(int32_t errorCode);

	void				SubEvent();
	void				UnSubEvent();

private:
	int32_t				mCollectSpeed;		//增加采集速度百分比
	SCurCollectState	m_curState;			//采集信息
};